﻿using System.Collections.Generic;

using LazyLib.ActionBar;
using LazyLib.Helpers;
using LazyLib.Combat;
using LazyLib.Wow;

using Frosty.Helpers;

namespace Frosty.Combat
{
    public class FrostSequence
    {
        
        public CombatResult FrostCombat(PUnit target)
        {

            if (!ObjectManager.MyPlayer.IsAutoAttacking)
                target.Interact();

            while (true)
            {
                Runes.CheckRunes();
                MoveHelper.MoveToUnit(target, CombatEngine.MeleeDistance);
                target.Face();

                // Multitarget or Singletarget
                List<PUnit> enemies = ObjectManager.GetAttackers;
                if (enemies.Count > 1)
                    MultiTarget(target);
                else
                    SingleTarget(target);
            }
        }

        public CombatResult SingleTarget(PUnit target)
        {
            /* http://elitistjerks.com/f72/t125291-frost_dps_4_2_against_all_odds/#Single_Target
             * Diseases
             * Obliterate if both Frost/Unholy pairs and/or both Death runes are up, or if Killing Machine is procced
             * Frost Strike if RP capped
             * Rime
             * Obliterate
             * Frost Strike
             * Horn of Winter
             */

            if (!ObjectManager.MyPlayer.IsAutoAttacking)
                target.Interact();

            do
            {
                // Try Outbreak First
                if (!ObjectManager.MyPlayer.Target.HasBuff(SpellIDs.FrostFever.Key) && !ObjectManager.MyPlayer.Target.HasBuff(SpellIDs.BloodPlague.Key) && BarMapper.IsSpellReadyById(SpellIDs.Outbreak.Key))
                {
                    BarMapper.CastSpell(SpellIDs.Outbreak.Value);
                }

                // Then Icy Touch
                else if (!ObjectManager.MyPlayer.Target.HasBuff(SpellIDs.FrostFever.Key) && BarMapper.IsSpellReadyById(SpellIDs.IcyTouch.Key) && Runes.FrostAvail())
                    BarMapper.CastSpell(SpellIDs.IcyTouch.Value);

                // Then Plague Strike
                else if (!ObjectManager.MyPlayer.Target.HasBuff(SpellIDs.BloodPlague.Key) && BarMapper.IsSpellReadyById(SpellIDs.PlagueStrike.Key) && Runes.UnholyAvail())
                    BarMapper.CastSpell(SpellIDs.PlagueStrike.Value);

                // Obliterate
                else if (ObjectManager.MyPlayer.RunicPower > 80)
                    BarMapper.CastSpell(SpellIDs.FrostStrike.Value);

                // Frost Strike
                else if (ObjectManager.MyPlayer.RunicPower > 80)
                    BarMapper.CastSpell(SpellIDs.FrostStrike.Value);

            } while (target.IsAlive);

            return CombatResult.Success;
        }

        public CombatResult MultiTarget(PUnit target)
        {
            /* http://elitistjerks.com/f72/t125291-frost_dps_4_2_against_all_odds/#Multiple_Target
             * Howling Blast if both Frost runes and/or both Death runes are up
             * Death and Decay if both Unholy Runes are up
             * Plague Strike if both Unholy Runes are up
             * Frost Strike if RP capped
             * Howling Blast
             * Frost Strike
             * Horn of Winter
             */
            return CombatResult.Success;
        }
    }
}
